package nsu.edu.zsq.util;

import java.lang.reflect.Field;
import java.util.List;

import nsu.edu.zsq.bean.SchMajor;
import nsu.edu.zsq.common.ApplicationContextHelper;
import nsu.edu.zsq.service.impl.sys.SchMajorServiceImpl;

/** 
* Description: 将majorNo专业代码转换为专业名称<br>
*/
public class TransformMajorNoUtil {

    /**
     * 将实体类中的majorNo专业代码数据转换为专业名称
     * @param objects 要转换的list数据
     * @throws Exception
     */
    public static void transformMajor(List<?> objects) throws Exception {
        SchMajorServiceImpl schMajorService = ApplicationContextHelper.popBean(SchMajorServiceImpl.class);
        List<SchMajor> listSchMajor = schMajorService.listSchMajor();
        for (Object object : objects) {
            Class<?> clazz = object.getClass();
            Field field = clazz.getDeclaredField("majorNo");
            field.setAccessible(true);
            String majorNo = (String)field.get(object);
            for (SchMajor schMajor : listSchMajor) {
                if (schMajor.getMajorNo().equals(majorNo)) {
                    field.set(object, schMajor.getMajorName());
                }
            }
        }
    }
}
